﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.HtmlControls;
using NPMonitor.DataModel.Report;
using NPMonitor.Implementation;
using NPMonitor.Utility;
using NPMonitor.DataModel;

namespace NPMonitor.Web.UserControls
{
    public partial class ReportActions : System.Web.UI.UserControl
    {
        #region Properties

        public string ScenarioNo { get; set; }

        public DateTime BeginTime { get; set; }

        public TimeSpan Duration { get; set; }

        #endregion

        #region Contructors

        public ReportActions()
        {
            BeginTime = DateTime.Now.AddHours(-1);
            Duration = TimeSpan.FromHours(1);
        }

        #endregion

        #region Page Event

        protected void Page_Load(object sender, EventArgs e)
        {
            BindTitle();

            BindData();
        }
         
        #endregion

        #region Methods

        public void BindData()
        {
            if (ScenarioNo != null)
            {
                List<HttpActionData> httpActions = StoreManager.Current.ReportStore.GetHttpActonList(ScenarioNo, BeginTime, Duration);

                BindTable(httpActions);
            }
        }

        protected void BindTitle()
        {
            if (ScenarioNo != null)
            {
                Scenario scenario = StoreManager.Current.JobDefinitionStore.GetAllScenarios(m => m.ScenarioNO == ScenarioNo).FirstOrDefault();

                if (scenario != null)
                {
                    this.ltScenario.Text = scenario.ScenarioName;
                    this.ltURL.Text = scenario.URL;
                    this.ltPageTitle.Text = "Welcome to DSM";
                    this.ltTime.Text = this.BeginTime.ToDateHourString();
                }
            }
        }

        protected void BindTable(IList<HttpActionData> httpActions)
        {
            if (httpActions != null && httpActions.Count > 0)
            {
                rptActionTable.DataSource = httpActions;
                rptActionTable.DataBind();
            }
        }

        #endregion
    }
}